package com.book.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.book.domain.DonateInsert;
import com.book.service.DonateListService;
import com.book.service.DonateTargetService;
import com.book.service.DonateTestBookamountService;
import com.book.service.MainService;

@Controller
public class MainController {

	@Autowired
	private MainService mainservice;
	@Autowired
	private DonateListService donateListService;
	@Autowired
	private DonateTargetService donateTargetService;
	@Autowired
	private DonateTestBookamountService donateTestBookamountService;

	@RequestMapping(value = "memberlist.do")
	public ModelAndView mainpage(Model model) {
		return new ModelAndView("memberlist");
	}

	@RequestMapping(value = "lookpassword.do")
	public ModelAndView lookpassword(Model model) {
		return new ModelAndView("lookpassword");
	}

	@RequestMapping(value = "emailcheck.do")
	public ModelAndView lookemail(Model model) {
		return new ModelAndView("emailcheck");
	}

	@RequestMapping(value = "emailpasswordcheck.do")
	public ModelAndView emailpasswordcheck(Model model) {
		return new ModelAndView("emailpasswordcheck");
	}

	@RequestMapping(value = "imagedown.do")
	public ModelAndView imagedown(Model model) {
		return new ModelAndView("bsyMypageNuserpage/imagedown");
	}

	@RequestMapping(value = "csjlookpassword.do")
	public ModelAndView csjlookpassword(Model model) {
		return new ModelAndView("csjLoginRegisterpage/csjlookpassword");
	}

	@RequestMapping(value = "csjemailpasswordcheck.do")
	public ModelAndView csjemailpasswordcheck(Model model,
			HttpServletRequest request) {

		return new ModelAndView("csjLoginRegisterpage/csjemailpasswordcheck");
	}

	@RequestMapping(value = "csjlookemail.do")
	public ModelAndView csjlookemail(Model model, HttpServletRequest request) {

		return new ModelAndView("csjLoginRegisterpage/csjlookemail");
	}

	@RequestMapping(value = "csjemailcheck.do")
	public ModelAndView csjemailcheck(Model model, HttpServletRequest request) {

		return new ModelAndView("csjLoginRegisterpage/csjemailcheck");
	}

	@RequestMapping(value = "csjinsert.do")
	public ModelAndView csjinsert(Model model, HttpServletRequest request) {

		return new ModelAndView("csjLoginRegisterpage/csjinsert");
	}

	@RequestMapping(value = "csjdonatelist.do")
	public ModelAndView donateList(Model model) {

		model.addAttribute("donateList", donateListService.getMember());

		return new ModelAndView("csjDonatepage/csjdonatelist");
	}

	@RequestMapping(value = "csjdonatetarget.do")
	public ModelAndView donateTarget(Model model) {

		model.addAttribute("donateTarget", donateTargetService.getMember());

		return new ModelAndView("csjDonatepage/csjdonatetarget");
	}

	@RequestMapping(value = "csjdonateinsert.do")
	public ModelAndView donateInsert(DonateInsert donateInsert, Model model,
			HttpServletRequest request) {

		System.out.println(request.getParameter("dcode"));
		System.out.println(request.getParameter("mcode"));
		System.out.println(request.getParameter("pbookamount"));
		
		donateInsert.setDcode(request.getParameter("dcode"));
		donateInsert.setMcode(request.getParameter("mcode"));
		donateInsert.setPbookamount(Integer.parseInt(request.getParameter("pbookamount")));
		
		donateTargetService.insertPatron(donateInsert);
		
		return new ModelAndView("csjDonatepage/csjdonateinsert");
	}

}
